package com.hehe.controller.my_space;

import com.hehe.POJO.User;
import com.hehe.Repository.UserRepository;
import com.hehe.Service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Slf4j
@Controller
@RequestMapping(value = "")
public class MySpaceController {

    @Value("${config_file_name}")
    private String config_file_name;

    @Resource
    private UserRepository userRepository;

    @Resource
    private UserService userService;



    @GetMapping(value = "/my-space")
    public String index(HttpServletRequest request, Model model) {
        log.info("my-space");
        String username = userService.get_username_by_cookie(request);
        if (username != null) {
            User user = userRepository.findByUsername(username);
            if (user != null) {
                model.addAttribute("username", user.getUsername());
                model.addAttribute("register_time", user.getRegister_time());
            }
        }
        model.addAttribute("username", username);
        return "my-space.html";
    }






}




